<template>
  <el-header>
    <div class="l-content">
      <el-button size="small" @click="handleCollapse">
        <el-icon :size="10"> <Menu /> </el-icon>
      </el-button>
      <el-breadcrumb separator="/" class="bread">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item :to="current.path" v-if="current">{{
          current.label
        }}</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="r-content">
      <el-dropdown>
        <span class="el-dropdown-link">
          <img :src="userImg()" class="user" />
        </span>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item>个人中心</el-dropdown-item>
            <el-dropdown-item @click.native="loginOut">退出</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </el-header>
</template>

<script>
import { computed } from "@vue/runtime-core";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
export default {
  setup() {
    let store = useStore();
    const router = useRouter();
    const userImg = () => {
      return new URL("../assets/images/user.jpg", import.meta.url).href;
    };
    let handleCollapse = () => {
      store.commit("updateIsCollapse");
    };

    //计算属性
    const current = computed(() => {
      return store.state.currentMenu;
    });
    const loginOut = () => {
      store.commit("clearToken");
      sessionStorage.clear();
      router.push({ name: "login" });
    };

    return {
      userImg,
      handleCollapse,
      current,
      loginOut,
    };
  },
};
</script>

<style lang="less" scoped>
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  background: #333;
  .l-content {
    .el-button {
      margin-right: 20px;
    }
    display: flex;
    align-items: center;
    h3 {
      color: #fff;
    }
    :deep(.bread span) {
      color: #fff;
      cursor: pointer;
    }
  }
  .r-content {
    .user {
      width: 45px;
      height: 45px;
      border-radius: 50%;
    }
  }
}
</style>
